<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ page import="com.conversationboard.model.*" %>
<%@ page import="com.conversationboard.view.*" %>
<%@ page import="com.conversationboard.config.*" %>
<%@ page import="java.util.List"%>
<%@ page import="com.conversationboard.cache.newanswers.NewAnswersThread"%>
<%@ page import="com.conversationboard.site.Site"%>
<%@ page import="java.security.*" %>

<%@page pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>

<% 
	List<NewAnswersThread> threads = (List<NewAnswersThread>) request.getAttribute("threads");
	Board board = (Board) request.getAttribute("board");
	User user = (User) request.getAttribute("user");
	Bookmarks bookmarks = user.getBookmarks();
	Principal principal = request.getUserPrincipal();
    request.setAttribute("activeUsers", Site.getCurrentlyActiveUsers());

	String noIndex = "";
	
	if (board.isNoIndex()) {
		noIndex = "<meta name=\"ROBOTS\" content=\"NOINDEX\"></meta>";	
	}
	
	OrderedBy orderedBy = OrderedBy.LAST_UPDATED;
	
	if (request.getAttribute("sort") != null) {
		orderedBy = OrderedBy.ALPHABETICAL;
	}

%>


<html>
	<head>
		<meta http-equiv="Pragma" content="no-cache" />
		<meta http-equiv="expires" content="0" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<%= noIndex %>
		<title><%=board.getName()%>: New Answers</title>
		<link rel="stylesheet" title="Conversation Board" type="text/css" href="<%=Configuration.getInstance().getRoot()%>/Stylesheets/<%=StyleSheets.getStyleSheetFileName(request.getCookies())%>">
		
		<c:if test="${user.admin}">
			<script src="${contextPath}/Javascript/style.js" type="text/javascript"></script>
		</c:if>
	</head>

	<body>
	
		<%= MenuDisplay.display(board, false, principal) %>
	
		<% if (SiteMessage.getMessage() != null) { %>	
		<div class='sitemessage'><%= SiteMessage.getMessage() %></div>
		<% } %>
		<% if (BatchMessage.getMessage() != null) { %>	
		<div class='batchmessage'><%= BatchMessage.getMessage() %></div>
		<% } %>

		<c:if test="${user.yellowCarded}">
			<div class="yellowcard">You Have Been Yellow Carded By a Moderator: ${user.yellowCardReason}</div>
		</c:if>
	
		<%= BookmarksDisplay.display(bookmarks, false) %>
	
		<div class="headingblock">
			<h1>New Answers: <%=board.getName()%></h1>
		</div>
		
		<div class="optionsblock">
			<!-- 
			<c:choose>
				<c:when test="${requestScope.sort}">
					<span class="leftmenulink"><a href="<%=Configuration.getInstance().getRoot()%>/NewAnswersControllerServlet?boardid=${board.boardId}">View By Most Recently Updated</a></span>
				</c:when>
				<c:otherwise>
					<span class="leftmenulink"><a href="<%=Configuration.getInstance().getRoot()%>/NewAnswersControllerServlet?boardid=${board.boardId}&sort=true">View In Alphabetical Order</a></span>
				</c:otherwise>
			</c:choose>
			-->
			
			<span class="leftmenulink">${activeUsers} Active Users</span>
			<span class="leftmenulink"><a title="Subscribe to a daily email update from the board" href="<%=Configuration.getInstance().getRoot()%>/Pages/confirmsubscription.jsp?action=subscribe&boardid=${board.boardId}">Subscribe</a> (unsubscribe in <a href="PrePreferencesControllerServlet">preferences</a>)</span>
			
		</div>
		

		<div class="mainblock">

			<%=	ThreadListDisplay.display(board, threads, user.getLoginId(), orderedBy) %>

			<a class="thread" href="<%=Configuration.getInstance().getRoot()%>/NewAnswersOnDateControllerServlet?weeksago=0&boardid=<%=board.getBoardId()%>">Show me threads that were last updated in the last week.</a><br />
			<a class="thread" href="<%=Configuration.getInstance().getRoot()%>/NewAnswersOnDateControllerServlet?weeksago=1&boardid=<%=board.getBoardId()%>">Show me threads that were last updated in the week before last.</a><br />
			<a class="thread" href="<%=Configuration.getInstance().getRoot()%>/NewAnswersOnDateControllerServlet?weeksago=2&boardid=<%=board.getBoardId()%>">Show me threads that were last updated between two and three weeks ago.</a><br />
			<a class="thread" href="<%=Configuration.getInstance().getRoot()%>/NewAnswersOnDateControllerServlet?weeksago=3&boardid=<%=board.getBoardId()%>">Show me threads that were last updated between three and four weeks ago.</a>

			<!-- <%= RecentHistoryDisplay.display(board, user) %>-->

			<% if (user.canAddUsersToBoard(board)) {%>

				<br /><br /><br />
			
				<form class="formsection" action="<%=Configuration.getInstance().getRoot()%>/Pages/confirmadduser.jsp?action=addusertoprivateboard" method="post">
					<h3>Add a new user to the board: <%= board.getName() %></h3>
				 	
				 	<input name="boardid" value="<%=board.getBoardId()%>" type="hidden" />
				 	
				 	<label for="email">Email Address as used for login ID:</label>
				 	<input name="email" class="smalltextbox" type="text" size="100" /><br /><br />
				 	
				 	<input type="submit" value="Add User" />

					<% if (user.isBoardAdmin(board.getBoardId())) { %>
						<p><a href="Admin/AdminPreRemoveUsersControllerServlet?boardid=${board.boardId}">Remove Users...</a></p>
					<% } %>

				</form>
				
							
			<% } %>

			
		</div>
		
		<!--<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>-->
		<!--<script type="text/javascript">_uacct = "UA-1148679-1";urchinTracker();</script>--> 
		
	</body>
	
</html>
